import { BaseLoginService } from './login.baseService';
import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
// import { TranslateService } from 'ng2-translate';

import {
    LoggerService, LoggerInfo, GeneralServiceProvider, ServiceDefinition, DataTypeEnum,
    ConfigService, ValidationService, ValidationType, StorageService, ContextService, PilotUser
} from '../../framework';

import { LoginServiceConfig } from './service/login.service.config';
import { ILoginConfig } from './module/login.module';

let defaultHtmlTemplate = require('./login.component.html');
let defaultStyles = {
    "default": require("!style/useable!css!sass!./assets/skin/classic/default.useable.scss"),
    "cyan": require("!style/useable!css!sass!./assets/skin/classic/cyan.useable.scss"),
    "red": require("!style/useable!css!sass!./assets/skin/classic/red.useable.scss"),
    "blue": require("!style/useable!css!sass!./assets/skin/classic/blue.useable.scss"),
};
 
let darkStyles = {
    "default": require("!style/useable!css!sass!./assets/skin/dark/default.useable.scss"),
    "cyan": require("!style/useable!css!sass!./assets/skin/dark/cyan.useable.scss"),
    "red": require("!style/useable!css!sass!./assets/skin/dark/red.useable.scss"),
    "blue": require("!style/useable!css!sass!./assets/skin/dark/blue.useable.scss"),
}

// var cnResource = require('./assets/i18n/zh-cn.json');
// var enResource = require('./assets/i18n/en-us.json');

@Component({
    selector: 'wit-login',
    template: defaultHtmlTemplate,
    providers: [LoggerService, BaseLoginService, ConfigService, ValidationService,
        {
            provide: GeneralServiceProvider,
            useFactory: () => {
                let definition: ServiceDefinition = new LoginServiceConfig().LoginRS();
                return new GeneralServiceProvider(definition);
            }
        }]
})

export class LoginComponent implements OnInit {
    style: string;
    teststring: string;
    @Input() loginConfig: ILoginConfig;
    //loginConfig: ILoginConfig;
    constructor(
        private mock: GeneralServiceProvider,
        private logger: LoggerService,
        private route: ActivatedRoute,
        private router: Router,
        private config: ConfigService,
        private val: ValidationService,
        private baseLoginService: BaseLoginService,
        //private translate: TranslateService
        ) {
        //this.mock.setConstructorParas(MockUsers);

        // translate.setTranslation('en-us', enResource);
        // translate.setTranslation('zh-cn', cnResource);
        // this.translate.setDefaultLang('en-us');
        // translate.use('zh-cn');
    }

    ngOnInit() {
        // A. DataSource sample
        // let para1 = {
        //     Where: `username = 'ZHAOYI121'`
        // }
        // this.mock.get(para1, function (data) {
        //     debugger;
        //     console.log(data);
        // }, function (data) {
        //     debugger;
        //     console.log(data);
        // });

        //  let para2 = {
        //      Items: {
        //          "username": "ZHAOYI22222",
        //          "firstName": "asd",
        //          "lastName": "asd",
        //          "zhFirstName": "ZHAO",
        //          "zhLastName": "YI",
        //          "legalEntity": "PASs",
        //          "desk": "SWAP",
        //          "userRole": "Trader",
        //          "userDomain": "SZ",
        //          "ibTraderId": "pazqdealer"
        //      }
        //  }
        //  this.mock.add(para2, function (data) {
        //      console.log(data);
        //  }, function (data) {
        //      console.log(data);
        //  });

        //  let para3 = {
        //      items: [{
        //          "mockid": 12,  //not work
        //          "username": "ZHAOYI22222",
        //          "firstName": "asd",
        //          "lastName": "asd",
        //          "zhFirstName": "ZHAO",
        //          "zhLastName": "YI",
        //          "legalEntity": "PASs",
        //          "desk": "SWAP",
        //          "userRole": "Trader",
        //          "userDomain": "SZ",
        //          "ibTraderId": "pazqdealer"
        //      }],
        //      where: `username = 'ZHAOYI' and desk = 'SWAP'`
        //  }
        //  this.mock.update(para3, function (data) {
        //      debugger;
        //      console.log(data);
        //  }, function (data) {
        //      debugger;
        //      console.log(data);
        //  });

        // let para4 = {
        //     Where: `username = 'ZHAOYI121'`
        // }
        // this.mock.delete(para4, function (data) {
        //     debugger;
        //     console.log(data);
        // }, function (data) {
        //     debugger;
        //     console.log(data);
        // });


        let layout = this.config.getValueByKey("wit-style");
        let skin = this.config.getValueByKey("wit-skin");
        this.style = layout;
        if (skin == null) skin = 'default';
        if (layout == null || layout == "classic") {

            defaultStyles[skin].use();

        } else {
            darkStyles[skin].use();

        }
    }

}
